package org.loneranger.p1_get_bean.demo;

import org.loneranger.p1_get_bean.bean.MyCat;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 编程方式创建bean对象
 *
 * @author shanzhenbo
 */
public class BeanDefinitionBeanTest {

	public static void main(String[] args) {

		AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext();

		AbstractBeanDefinition beanDefinition =
				BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();

		beanDefinition.setBeanClass(MyCat.class);

		applicationContext.registerBeanDefinition("myCat", beanDefinition);

		applicationContext.refresh();

		MyCat myCat = applicationContext.getBean("myCat", MyCat.class);

		myCat.miao();


	}
}
